Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server/errors): error messages can use message template format #3160

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iainsproat
Copy link
Contributor

@iainsproat iainsproat commented Sep 27, 2024

Description & motivation

Errors derived from vError can attach properties to info parameter of the options object when constructed.

These info properties can now be used to populate a string template in the error's message. The message template follows pino pretty format.

This reduces the cardinality of errors, enabling similar errors to be simply searchable using the template string.

The code is modified from pino-pretty repository, licensed under an MIT license.

Changes:

  • The server's default error handler will populate the error message template before returning the error to the client.
  • Tests are included for the message templating.

Additional minor changes:

  • The status code is included in the response log message template by the pino http logger.

To-do before merge:

Validation of changes:

The server logs the template and properties separately:

Screenshot 2024-09-27 at 17 10 27

The client sees the formatted message, with the template populated with the data:

Screenshot 2024-09-27 at 17 19 07

Checklist:

  • My pull request follows the guidelines in the Contributing guide?
  • My pull request does not duplicate any other open Pull Requests for the same update/change?
  • My commits are related to the pull request and do not amend unrelated code or documentation.
  • My code follows a similar style to existing code.
  • I have added appropriate tests.
  • I have updated or added relevant documentation.

References

@iainsproat iainsproat marked this pull request as ready for review September 27, 2024 16:36
@gjedlicska
Copy link
Contributor

tbf, this feels like an overkill, what are the error message examples, that we're trying to bundle into a single type with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants